//
//  JiexiaoJoinStyleCell.swift
//  HappyEat
//
//  Created by ctx2016 on 17/1/20.
//  Copyright © 2017年 陌路是我. All rights reserved.
//

import UIKit

class JiexiaoJoinStyleCell: UITableViewCell {
    
    var imageNames:[String] = ["ic_D","ic_C","ic_J","ic_L"]
    var titleNames:[String] = ["一象牙参与","筹满揭晓","揭晓告示","领取宝贝"]

    override func awakeFromNib() {
        super.awakeFromNib()
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
}
extension JiexiaoJoinStyleCell{
    func setUI(){
        let joinLabel:UILabel = UILabel.init()
        let headIcon:UIImageView = UIImageView.init()
        let seeDetail:UILabel = UILabel.init()
        self.contentView.addSubview(joinLabel)
        self.contentView.addSubview(headIcon)
        self.contentView.addSubview(seeDetail)
        seeDetail.font = UIFont.systemFont(ofSize: 12)
        seeDetail.textColor = BaseFontColor
        joinLabel.snp.makeConstraints { (make) in
            make.left.equalTo(16)
            make.width.equalTo(100)
            make.top.equalTo(12)
            make.height.equalTo(16)
        }
        joinLabel.text = "参与方式"
        seeDetail.text = "查看规则"
        seeDetail.snp.makeConstraints { (make) in
            make.width.equalTo(seeDetail.width(forText: "查看规则", withFontSize: 12, withTextHeight: 16))
            make.top.equalTo(joinLabel)
            make.height.equalTo(16)
            make.right.equalTo(-16)
        }
        headIcon.contentMode = .scaleAspectFit
        headIcon.snp.makeConstraints { (make) in
            make.right.equalTo(seeDetail.snp.left).offset(-5)
            make.size.equalTo(CGSize.init(width: 10, height: 10))
            make.top.equalTo(seeDetail.snp.top).offset(3)
        }
        headIcon.image = UIImage.init(named: "ic_i")
        let itemWidth:CGFloat = k_Wide/4
        for i in 0 ..< 4 {
            let imageView:UIImageView = UIImageView.init(image: UIImage.init(named: imageNames[i]))
            let bgView:UIView = UIView.init()
            self.contentView.addSubview(bgView)
            bgView.addSubview(imageView)
            let titleLabel:UILabel = UILabel.init()
            self.contentView.addSubview(titleLabel)
            titleLabel.textColor = BaseFontColor
            titleLabel.font = UIFont.systemFont(ofSize: 12)
            titleLabel.text = titleNames[i]
            titleLabel.textAlignment = .center
            bgView.snp.makeConstraints({ (make) in
                make.left.equalTo(CGFloat(i) * itemWidth)
                make.size.equalTo(CGSize.init(width:itemWidth, height: 25))
                make.top.equalTo(joinLabel.snp.bottom).offset(12)
            })
            imageView.snp.makeConstraints({ (make) in
                make.top.equalTo(0)
                make.bottom.equalTo(0)
                make.left.equalTo((itemWidth - 25)/2)
                make.width.equalTo(25)
            })
            titleLabel.snp.makeConstraints({ (make) in
                make.left.equalTo(bgView)
                make.right.equalTo(bgView)
                make.top.equalTo(bgView.snp.bottom).offset(8)
                make.height.equalTo(12)
            })
            if i != 3{
                let iconJt:UIImageView = UIImageView.init()
                bgView.addSubview(iconJt)
                iconJt.image = UIImage.init(named: "ic_zd")
                iconJt.snp.makeConstraints({ (make) in
                    make.left.equalTo(bgView.snp.right).offset(-(itemWidth-25)/4)
                    make.size.equalTo(CGSize.init(width: 5, height: 7))
                    make.top.equalTo(bgView.snp.top).offset(9)
                })
            }
        }
    }
}
